<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>加法器</title>
</head>
<body>
加法器<br />
<input type="text" id="txt1" /> +
<input type="text" id="txt2" /> =
<input type="text" id="txt3" readonly/>
<input type="button" id="btnl" value="计算" />

<script>
// 定义加法函数
function addNumbers() {
  // 获取输入框的值
  const num1 = parseFloat(document.getElementById('txt1').value);
  const num2 = parseFloat(document.getElementById('txt2').value);

  // 计算和
  const sum = num1 + num2;

  // 将结果显示在第三个文本框中
  document.getElementById('txt3').value = sum;
}

// 当页面加载完成时设置按钮点击事件
  document.addEventListener('DOMContentLoaded', (event) => {
  const btn = document.getElementById('btnl');
  btn.addEventListener('click', addNumbers);
});
</script>

</body>
</html>